package com.qys.livesMall.event.listener;

import com.qys.livesMall.app.user.event.UserRechargeEvent;
import com.qys.livesMall.app.user.model.dto.sys.UserRechargeDTO;
import com.qys.livesMall.app.user.service.UserStatisticsInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Slf4j
@RequiredArgsConstructor
public class UserRechargeListener {

    private final UserStatisticsInfoService userStatisticsInfoService;

    /**
     * 用户提现充值监听
     * @param userRechargeEvent
     */
    @Async
    @Order
    @EventListener(UserRechargeEvent.class)
    public void saveUserRechargeInfo(UserRechargeEvent userRechargeEvent){
        UserRechargeDTO userRechargeDTO= (UserRechargeDTO) userRechargeEvent.getSource();
        userStatisticsInfoService.updatebyUserid(userRechargeDTO);
    }
}
